# The primary targets in this file are:
#
# pdf         Generate the PDF for all documents
# html        Generate the HTML for all documents
# clean       Clean up generated files

XMLTO       := xmlto
FOP         := fop
RM          := rm -f

VISION_DIR  := vision
UC_DIR      := UC

VISION_XML_SOURCES  := $(wildcard $(VISION_DIR)/*.xml)
UC_XML_SOURCES      := $(wildcard $(UC_DIR)/*.xml)

VISION_FO_TARGETS   := $(subst .xml,.fo,$(VISION_XML_SOURCES))
UC_FO_TARGETS       := $(subst .xml,.fo,$(UC_XML_SOURCES))

VISION_FO_TARGETS   := $(subst .xml,.fo,$(VISION_XML_SOURCES))
UC_FO_TARGETS       := $(subst .xml,.fo,$(UC_XML_SOURCES))

VISION_PDF_TARGETS  := $(subst .xml,.pdf,$(VISION_XML_SOURCES))
UC_PDF_TARGETS      := $(subst .xml,.pdf,$(UC_XML_SOURCES))

VISION_HTML_TARGETS := $(subst .xml,.html,$(VISION_XML_SOURCES))
UC_HTML_TARGETS     := $(subst .xml,.html,$(UC_XML_SOURCES))

ALL_FO_TARGETS      := $(VISION_FO_TARGETS) $(UC_FO_TARGETS)
ALL_PDF_TARGETS     := $(VISION_PDF_TARGETS) $(UC_PDF_TARGETS)
ALL_HTML_TARGETS    := $(VISION_HTML_TARGETS) $(UC_HTML_TARGETS)

FO_STYLESHEET       := stylesheet.fo.xsl
HTML_STYLESHEET     := stylesheet.html.xsl

%.fo: %.xml
	$(XMLTO) -m $(dir $<)$(FO_STYLESHEET) -o $(dir $<) fo $< 

%.pdf: %.fo
	$(FOP) $< $@

%.html: %.xml
	$(XMLTO) -m $(dir $<)$(HTML_STYLESHEET) -o $(dir $<) xhtml-nochunks $<

.PHONY: pdf html clean

pdf: $(ALL_PDF_TARGETS)

html: $(ALL_HTML_TARGETS)

clean:
	$(RM) $(ALL_FO_TARGETS)
	$(RM) $(ALL_PDF_TARGETS)
	$(RM) $(ALL_HTML_TARGETS)

